/*
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.subshell.lucene.indexaccess;

import java.io.IOException;
import java.util.Set;

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.store.Directory;

/**
 * Provides low-level access to an index.
 * 
 * @author Maik Schreiber (blizzy AT blizzy DOT de)
 */
public interface IIndexAccessProvider {

    /**
     * Opens an IndexReader.
     * 
     * @return An index reader.
     * @throws IOException
     *             If there is an error getting the index reader.
     */
    IndexReader getReader() throws IOException;

    /**
     * Opens an IndexWriter.
     * 
     * @return An index writer.
     * @throws IOException
     *             If there is an error getting the index writer.
     */
    IndexWriter getWriter() throws IOException;

    /**
     * Opens a Searcher.
     * <p>
     * In the case of <code>underlyingSearchers</code> being non-null and
     * non-empty, a MultiSearcher is returned.
     * 
     * @param similarity
     *            The similarity.
     * @param underlyingSearchers
     *            The underlying searchers.
     * @return A searcher.
     * @throws IOException
     *             If there is an error getting the searcher.
     */
    Searcher getSearcher(Similarity similarity, Set underlyingSearchers)
            throws IOException;

    /**
     * Opens a Directory.
     * 
     * @return A directory.
     * @throws IOException
     *             If there is an error getting the directory.
     */
    Directory getDirectory() throws IOException;

    /**
     * Closes an IndexReader.
     * 
     * @param reader
     *            The index reader to close.
     */
    void close(IndexReader reader);

    /**
     * Closes an IndexWriter.
     * 
     * @param writer
     *            The index writer to close.
     */
    void close(IndexWriter writer);

    /**
     * Closes a Searcher.
     * 
     * @param searcher
     *            The searcher to close.
     */
    void close(Searcher searcher);

    /**
     * Closes a Directory.
     * 
     * @param directory
     *            The directory to close.
     */
    void close(Directory directory);
}
